/*
 * Ken Anderson, 2009
 */

#ifndef EVENT_HANDLER_H
#define EVENT_HANDLER_H

#ifdef WIN32
#include <SDL.h>
#include <SDL_OpenGL.h>
#else
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>

#endif

// These variables are shared between the event handler, visualizer, and renderer
class WorldState
{
public:
	bool mDone;
	bool mResetWindow;
	int  mWindowWidth;
	int  mWindowHeight;
	bool mNewStart;
	bool mNewGoal;
	bool mCycleSearch;
	float mFrameRate;

	// Viewer's orientation
	GLfloat zDistance;
	GLfloat xOffset;
	GLfloat yOffset;
	GLfloat mXRotationAngle;
	GLfloat mYRotationAngle;

	// Show/Hide objects
	bool mShowLevel0;
	bool mShowLevel1;
	bool mShowLevel2;

	// Keyboard movement
	bool mKeyRotateLeft;
	bool mKeyRotateRight;
	bool mKeyRotateUp;
	bool mKeyRotateDown;
	bool mKeyScrollLeft;
	bool mKeyScrollRight;
	bool mKeyScrollUp;
	bool mKeyScrollDown;
	bool mKeyZoomIn;
	bool mKeyZoomOut;

	// Constructor / Destructor
	WorldState();
	~WorldState();
};

// Handles input / output from keyboard:
//   Scroll with arrow keys or right mouse button.
//   Zoom with +/- or middle mouse button.
//   Rotate with left mouse button.
//   New starting state with 't'.
//   New goal state with 'g'.
//   Cycle through heuristics with 's'.
//   Toggle graph levels with '0', '1', or '2', when appropriate.
//   Quit with ESC.
class EventHandler
{
	WorldState * mWorldState;
	bool mMouseLeft;
	bool mMouseMiddle;
	bool mMouseRight;
	
	void HandleUserEvent(SDL_Event* event);
	void HandleWindowResize( SDL_ResizeEvent* resize );
	void HandleKeyDownEvent(SDL_keysym* keysym);
	void HandleKeyUpEvent(SDL_keysym* keysym);
	void HandleMouseButtonEvent( SDL_MouseButtonEvent* button );
	void HandleMouseMotionEvent( SDL_MouseMotionEvent* motion );

public:
	// Constructor
	EventHandler(WorldState * worldState);

	// Respond to a system event
	void HandleEvent(SDL_Event* event);
};


#endif
